package com.soup.lab.executor;

import com.soup.lab.tools.mtt.MultiThreadTestUtils;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class FutureTestCase {

    private static Logger logger = LoggerFactory.getLogger(FutureTestCase.class);

    @Test
    public void test() throws ExecutionException, InterruptedException {
        FutureTask<Integer> future = new FutureTask(() -> {
            TimeUnit.SECONDS.sleep(5);
            logger.info("run me");
            return 100;
        });
        MultiThreadTestUtils.run(3, () -> {
            try {
                future.run();
                logger.info("{}", future.get());
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        });
    }



}
